// 计算日期范围和间隔
function calculateDateRange(type) {
  const endDate = new Date();
  let startDate;
  let interval = 'day'; // 默认按天聚合

  if (type === 'week') {
    startDate = new Date();
    startDate.setDate(endDate.getDate() - 6); // 最近7天
  } else if (type === 'month') {
    startDate = new Date();
    startDate.setDate(endDate.getDate() - 29); // 最近30天
  } else {
    // 默认为周
    startDate = new Date();
    startDate.setDate(endDate.getDate() - 6);
  }

  // 设置时间为当天的开始和结束
  startDate.setHours(0, 0, 0, 0);
  endDate.setHours(23, 59, 59, 999);

  return { startDate, endDate, interval };
}

module.exports = { calculateDateRange };